package Frame;

import java.awt.BorderLayout;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.awt.event.MouseEvent;
import java.awt.event.MouseMotionListener;
import java.sql.ResultSet;
import java.util.ArrayList;
import java.util.List;
import java.util.Vector;

import javax.swing.BorderFactory;
import javax.swing.JButton;
import javax.swing.JLabel;
import javax.swing.JOptionPane;
import javax.swing.JPanel;
import javax.swing.JScrollPane;
import javax.swing.JTable;
import javax.swing.JTextField;

import Dao.DaoSqlData;
import Rule.NameTag;
import Table.MyTable;

public class ManagerUpdatePanel extends JPanel{

	final JScrollPane scrollPane;
	static JButton Button_serch_2; //被修改对话框调用，刷新页面
	private JTextField TextField_Name;
	
	public ManagerUpdatePanel(){
		
		JLabel Label_Name = new JLabel(NameTag.common_Name);
		TextField_Name = new JTextField("",8);
		Button_serch_2 = new JButton(NameTag.serch_2);
		Button_serch_2.addActionListener(new ButtonActionListener());
		JPanel panel_1 = new JPanel();
		panel_1.add(Label_Name);
		panel_1.add(TextField_Name);
		panel_1.add(Button_serch_2);
		
		scrollPane=new JScrollPane();
		scrollPane.setBorder(BorderFactory.createTitledBorder(NameTag.common_Tittle));	
		scrollPane.setVerticalScrollBarPolicy(JScrollPane.VERTICAL_SCROLLBAR_ALWAYS);
		
		this.setLayout(new BorderLayout());	
		this.add(panel_1, BorderLayout.NORTH);
		this.add(scrollPane, BorderLayout.CENTER);
			
	}
	
	private class ButtonActionListener implements ActionListener {

		@Override
		public void actionPerformed(ActionEvent arg0) {
				
			Vector rows = null; 
			String sqlField_1 = "prd_Name" ;
			String sqlField_2 = TextField_Name.getText().trim();
			
			try {
				ResultSet rs = DaoSqlData.getPrdtInfoByAsc(sqlField_1,sqlField_2);
				if(! rs.isBeforeFirst()){
					JOptionPane.showMessageDialog(scrollPane, "查询不到任何数据！");
					TextField_Name.requestFocus();//获得焦点
					TextField_Name.selectAll();
					return;
				}		
				rows = new Vector();		
				while(rs.next()){
					Vector currow = new Vector();
					currow.add(rs.getString(2));
					currow.add((rs.getInt(3)));
					currow.add((rs.getFloat(4)));
					currow.add((rs.getInt(1)));
					rows.add(currow);
				}
			} catch (Exception e) {
				
				e.printStackTrace();
			}				
			MyTable mytable = MyTable.getTable(rows,true,true);
		 	scrollPane.setViewportView(mytable);
		
		}
		
	}

}
